<?php
global $_W, $_GPC;
$uniacid = $_W['uniacid'];
$setting = $this->baseset($uniacid);
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ('del' == $op) {
	$id = intval($_GPC['id']);
	$row = pdo_fetch("SELECT id FROM " . tablename($this->tableorderus) . " WHERE id = :id", array(':id' => $id));
	if (empty($row)) {
		message('订单不存在！');
	}
	pdo_delete($this->modulename . '_orderus', array('id' => $id));
	message('删除成功！', referer(), 'success');
} else if ('delall' == $op) {
	$ids = $_GPC['ids'];
	foreach ($ids as $id) {
		pdo_delete($this->modulename . '_orderus', array('id' => $id));
	}
	message('删除' . $id . '成功！', referer(), 'success');
} else if ('display' == $op) {
	$condition1 = "";
	$condition2 = "";
	$condition4 = "";
	if (!empty($_GPC['keyword'])) {
		$condition1 .= " AND CONCAT(`itemtitle`,`itemid`,`orderid`) LIKE '%{$_GPC['keyword']}%'";
	}
	if (!empty($_GPC['itemstatus'])) {
		$condition2 .= " AND CONCAT(`itemstatus`) = '{$_GPC['itemstatus']}'";
	}
	if (!empty($_GPC['id'])) {
		$condition4 .= " AND CONCAT(`id`) = '{$_GPC['id']}'";
	}
	$pindex = max(1, intval($_GPC['page']));
	if ($_GPC['psize']) {
		$psize = $_GPC['psize'];
	} else {
		$psize = 10;
	}
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableorderus) . " WHERE uniacid = '{$_W['uniacid']}' $condition1 $condition2 $condition4 order by ctime desc,id desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	foreach ($list as $item => $xfgw) {
		$orderinfo = pdo_fetch("SELECT * FROM " . tablename($this->tableorder) . " WHERE uniacid = '{$_W['uniacid']}' AND orderid = '{$list[$item]['orderid']}' LIMIT 1");
		if ($orderinfo) {
			$list[$item]['oredrok'] = 1;
			$list[$item]['orderid2'] = $orderinfo['orderid'];
			$list[$item]['orderfee2'] = $orderinfo['orderfee'];
			$list[$item]['orderstatus2'] = $orderinfo['orderstatus'];
			$list[$item]['shouru_yongjin2'] = $orderinfo['shouru_yongjin'];
			$list[$item]['shouru_bili2'] = $orderinfo['shouru_bili'];
		} else {
			$list[$item]['oredrok'] = 0;
			$list[$item]['orderfee2'] = 0;
			$list[$item]['orderstatus2'] = 0;
			$list[$item]['shouru_yongjin2'] = 0;
			$list[$item]['shouru_bili2'] = 0;
		}
	}
	$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($this->tableorderus) . " WHERE uniacid = '{$_W['uniacid']}' $condition1 $condition2 $condition4");
	$pager = pagination($total, $pindex, $psize);
} else if ('status' == $op) {
	$id = $_GPC['id'];
	pdo_query('update ' . tablename($this->tableorderus) . " set status = !status where id='{$id}'");
	die('1');
}
include $this->template('listorderus');